<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/taglib.jsp" %>

<html>
<head>
    <title>微社区|Q生活</title>
    <link rel="stylesheet" href="${ctx }/static/css/Master.css"/>
    
    <link rel="stylesheet" href="${ctx}/static/css/css.css">
    <link rel="stylesheet" href="${ctx}/static/plugins/jquery-treetable/stylesheets/jquery.treetable.css">
    <link rel="stylesheet" href="${ctx}/static/plugins/jquery-treetable/stylesheets/jquery.treetable.theme.default.css">
    <script src="${ctx}/static/js/jquery-1.9.0.min.js"></script>
	<script src="${ctx}/static/plugins/jquery-treetable/javascripts/src/jquery.treetable.js"></script>
	<script src="${ctx}/static/plugins/layer/layer.js"></script>
	<%-- 基础js,所有页面都需要引入此js,依赖layer.js --%>
	<script src="${ctx}/static/js/common/base.js"></script>
	<style type="text/css">
        #table th, #table td {
            font-size: 14px;
            padding : 8px;
            line-height: 24px;
		    padding: 6px 5px;
		    text-align: center;
        }
        table.treetable{
		  border: 1px solid #fff;
		  /*text-align: center;*/
		}
        table.treetable thead tr th{
		  background: #f35e0b;
		  color: #fff;
		  border: 1px solid #fff;
		  text-align: center;
		}
    </style>
	<script type="text/javascript">
	    $(function() {
	        $("#table").treetable({ 
	        	expandable: true
	        	,onNodeCollapse: function(){
	        		setBackColor();
	        	}
	        	,onNodeExpand: function(){
	        		setBackColor();
	        	}
	        }).treetable("expandNode", 1);
	        
	    });
	    
	    //启用/停用
	    function doEnableOrDisable(id,normal,name){
	    	var msg = '确认'+(normal==1?'停用':'启用')+'"'+name+'"吗?';
	    	top.layer.confirm(msg, {icon: 3}, function(index){
	    		$.ajax({    
	    		    url:"${ctx}/resource/"+id+"/"+normal+"/updateToEnableOrDisable",   
	    		    data:"",    
	    		    type:"get",    
	    		    cache:false,    
	    		    dataType:"json",
	    		    async:true, //默认为true 异步    
	    		    success:function(data) {
    		            top.layer.msg(data,{},function(){
    			        	window.location.reload();   
    		            });
	    		     }  
	    		});
	    	});
	    }
	    
	    //删除
	    function del(id,name) {
	    	top.layer.confirm('如果有子资源,会一并删除!<br>确认删除"'+name+'"吗?', {icon: 3}, function(index){
	    		$.ajax({    
	    		    url:"${ctx}/resource/"+id+"/delete",   
	    		    data:"",    
	    		    type:"get",    
	    		    cache:false,    
	    		    dataType:"json",
	    		    async:true, //默认为true 异步    
	    		    success:function(data) {    
    		            top.layer.msg(data,{},function(){
    			        	window.location.reload();   
    					});
	    		     }  
	    		});
	    	});
            
        }
	    
	    // 设置table奇偶行的颜色
	    function setBackColor(){
	    	setTimeout(function(){
		    	$("#table tr:visible:odd").css("background-color", "#FFFFFF"); 
		    	$("#table tr:visible:even").css("background-color", "#F0F0F0"); 
	    	},200);
	    	
	    }
	</script>
</head>
<body>
<section class="boxRight">
<div class="context boxborder">

<table id="table">
    <thead>
        <tr>
            <th>名称</th>
            <th>类型</th>
            <th>权限字符串</th>
            <th>菜单URL</th>
            <th>菜单顺序</th>
            <th>菜单样式</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        <c:forEach items="${list}" var="resource">
            <tr data-tt-id='${resource.resId}' <c:if test="${not (resource.resLevel == 1)}">data-tt-parent-id='${resource.resPId}'</c:if>>
                <td>${resource.resName}</td>
                <td style="text-align: center;">${(resource.resLevel == 1)?'':diy:keyToValue(resource.resType,'RESOURCE_TYPE')}</td>
                <td style="text-align: left;">${resource.resPermission}</td>
                <td style="text-align: center;">${resource.resUrl}</td>
                <td style="text-align: right;">${resource.resOrder}</td>
                <td style="text-align: center;">${resource.resClass}</td>
                <td style="text-align: center;">${diy:keyToValue(resource.normal,'NORMAL')}</td>
                <td style="text-align: center;">
                  <c:if test="${not (resource.resLevel == 1)}">
	                  <shiro:hasPermission name="sys:resource:view">
						<a class="icon micon_9" title="详情" href="${ctx}/resource/${resource.resId}/detail"></a>
					  </shiro:hasPermission>
				  </c:if>
                  <c:if test="${resource.resType == 1 || resource.resLevel == 1}">
                  	<shiro:hasPermission name="sys:resource:create">
                      <a class="icon micon_24" title="添加子节点" href="${ctx}/resource/${resource.resId}/create"></a>
                 	 </shiro:hasPermission>
                  </c:if>

                  <c:if test="${not (resource.resLevel == 1)}">
                    <shiro:hasPermission name="sys:resource:update">
                      <a class="icon micon_2" title="编辑" href="${ctx}/resource/${resource.resId}/update"></a>
                    </shiro:hasPermission>
                  </c:if>
                  <c:if test="${not (resource.resLevel == 1)}">
                  	<shiro:hasPermission name="sys:resource:start/stop">
	                    <c:if test="${resource.normal == 1}">
	                    <a class="icon micon_1" title="停用" href="javascript:void(0);" onclick="doEnableOrDisable('${resource.resId}',${resource.normal},'${resource.resName}')"></a>
	                    </c:if>
	                    <c:if test="${resource.normal == 0}">
	                    <a class="icon micon_12" title="启用" href="javascript:void(0);" onclick="doEnableOrDisable('${resource.resId}',${resource.normal},'${resource.resName}')"></a>
	                    </c:if>
	                </shiro:hasPermission>
                    <shiro:hasPermission name="sys:resource:delete">
                      <a class="icon micon_20" title="删除" href="javascript:void(0);" onclick="del('${resource.resId}','${resource.resName}');" ></a>
                    </shiro:hasPermission>
                  </c:if>
                </td>
            </tr>
        </c:forEach>
    </tbody>
</table>
</div>
</section>
</body>
</html> 